package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.Func;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TFzsczLogEntity;
import com.company.project.service.TFzsczLogService;



/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-29 19:15:56
 */
@Controller
@RequestMapping("/")
public class TFzsczLogController {
    @Autowired
    private TFzsczLogService tFzsczLogService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tFzsczLog")
    public String tFzsczLog() {
        return "tfzsczlog/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tFzsczLog/add")
    @RequiresPermissions("tFzsczLog:add")
    @ResponseBody
    public DataResult add(@RequestBody TFzsczLogEntity tFzsczLog){
        tFzsczLogService.save(tFzsczLog);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tFzsczLog/delete")
    @RequiresPermissions("tFzsczLog:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tFzsczLogService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tFzsczLog/update")
    @RequiresPermissions("tFzsczLog:update")
    @ResponseBody
    public DataResult update(@RequestBody TFzsczLogEntity tFzsczLog){
        tFzsczLogService.updateById(tFzsczLog);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tFzsczLog/listByPage")
    @RequiresPermissions("tFzsczLog:list")
    @LogAnnotation(title = "分钟数重置", action = "查询分页数据")

    @ResponseBody
    public DataResult findListByPage(@RequestBody TFzsczLogEntity tFzsczLog){
        Page page = new Page(tFzsczLog.getPage(), tFzsczLog.getLimit());
        LambdaQueryWrapper<TFzsczLogEntity> queryWrapper = Wrappers.lambdaQuery();
//        queryWrapper.apply(" where userid in (select userid from ");
        queryWrapper.gt(TFzsczLogEntity::getCzfzs,"0");
        if (Func.isNotEmpty(tFzsczLog.getUserid())) queryWrapper.like(TFzsczLogEntity::getUserid,tFzsczLog.getUserid());

        queryWrapper.orderByDesc(TFzsczLogEntity::getCztime);
        //查询条件示例
        //queryWrapper.eq(TFzsczLogEntity::getId, tFzsczLog.getId());
        IPage<TFzsczLogEntity> iPage = tFzsczLogService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
